<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>控制面板</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
    <!-- 添加API和状态管理脚本 -->
    <script src="/assets/js/api.js"></script>
    <script src="/assets/js/state.js"></script>
    <script src="/assets/js/loading.js"></script>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        /* 修改主容器样式 */
        .container {
            height: 100vh;
            overflow: hidden;
        }

        body {
            font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
            background-color: #f5f6fa;
            margin: 0;
            padding: 0;
            color: #2d3436;
            min-height: 100vh;
            overflow: hidden;
        }

        .dashboard {
            max-width: 100%;
            height: calc(100vh - 32px); /* 减去顶部padding */
            margin: 0;
            display: grid;
            grid-template-columns: 300px minmax(0, 1fr);
            gap: 20px;
            padding: 16px;
            padding-bottom: 24px; /* 增加底部内边距 */
            overflow: hidden;
        }

        .left-panel, .right-panel {
            display: flex;
            flex-direction: column;
            gap: 24px;
            height: 100%;
            overflow-y: auto;
            padding-right: 8px;
            padding-bottom: 16px; /* 添加底部内边距 */
        }

        /* 添加滚动条美化样式 */
        .left-panel::-webkit-scrollbar,
        .right-panel::-webkit-scrollbar {
            width: 6px;
        }

        .left-panel::-webkit-scrollbar-thumb,
        .right-panel::-webkit-scrollbar-thumb {
            background-color: rgba(0, 0, 0, 0.1);
            border-radius: 3px;
        }

        .left-panel::-webkit-scrollbar-track,
        .right-panel::-webkit-scrollbar-track {
            background-color: transparent;
        }

        /* 控制台区域自适应高度调整 */
        .console-wrapper {
            flex: 1;
            min-height: 180px;
            max-height: calc(100vh - 520px); /* 调整最大高度 */
            overflow: hidden;
            margin-bottom: 16px; /* 添加底部间距 */
        }

        .console {
            height: 100%;
            overflow-y: auto;
            background: #1e2227;
            border-radius: 12px;
            padding: 16px;
            font-size: 13px;
            line-height: 1.5;
        }

        /* 响应式布局优化 */
        @media (max-width: 1200px) {
            .dashboard {
                grid-template-columns: 280px minmax(0, 1fr);
            }
        }

        @media (max-width: 992px) {
            .dashboard {
                height: auto;
                min-height: calc(100vh - 32px);
                overflow-y: auto;
                padding-bottom: 32px; /* 移动端增加更多底部空间 */
            }

            .left-panel {
                display: grid;
                grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
                gap: 16px;
            }

            .left-panel, .right-panel {
                height: auto;
                overflow: visible;
            }

            .console-wrapper {
                max-height: 400px;
            }
        }

        /* 移除自定义标题栏相关样式 */
        .window-titlebar,
        .window-controls,
        .window-control-button {
            display: none;
        }

        /* 移除顶部padding */
        .dashboard {
            padding-top: 10px !important; /* 覆盖内联样式 */
        }

        /* 添加版本号样式 */
        .version-info {
            position: fixed;
            bottom: 16px;
            left: 16px;
            font-size: 11px;
            color: #666;
            opacity: 0.8;
            z-index: 1000;
            background: rgba(255, 255, 255, 0.9);
            padding: 4px 8px;
            border-radius: 4px;
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
        }


        .left-panel .panel-section:first-child {
            flex: 0 0 auto; /* 用户信息固定高度 */
        }

        .left-panel .panel-section:nth-child(2) {
            flex: 0 0 auto; /* 快捷操作固定高度 */
        }

        .left-panel .panel-section:last-child {
            flex: 1; /* Token使用情况占据剩余空间 */
        }

        .right-panel .panel-section:first-child {
            flex: 0 0 auto; /* Token统计固定高度 */
        }

        .right-panel .panel-section:nth-child(2) {
            flex: 0 0 auto; /* 操作面板固定高度 */
        }

        .right-panel .panel-section:last-child {
            flex: 1; /* 运行日志占据剩余空间 */
            display: flex;
            flex-direction: column;
        }

        .panel-section {
            background: white;
            border-radius: 12px;
            padding: 16px;
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
            transition: all 0.3s ease;
            margin-bottom: 12px;
        }

        .panel-section:hover {
            transform: translateY(-2px);
            box-shadow: 0 6px 20px rgba(0, 0, 0, 0.1);
        }

        /* 用户信息区域样式还原 */
        .user-info {
            display: flex;
            align-items: center;
            gap: 16px;
            padding: 24px;
            background: linear-gradient(135deg, #4776E6 0%, #8E54E9 100%);
            border-radius: 16px;
            color: white;
            position: relative;
            overflow: hidden;
        }

        .avatar {
            width: 56px;
            height: 56px;
            min-width: 56px;
            background: rgba(255, 255, 255, 0.2);
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            border: 2px solid rgba(255, 255, 255, 0.3);
        }

        .avatar i {
            font-size: 24px;
            color: rgba(255, 255, 255, 0.9);
        }

        .user-details {
            flex: 1;
            min-width: 0;
        }

        .user-details h2 {
            font-size: 18px;
            font-weight: 600;
            color: white;
            margin-bottom: 8px;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }

        .user-details p {
            font-size: 14px;
            color: rgba(255, 255, 255, 0.9);
            margin-bottom: 8px;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }

        .user-role {
            font-size: 12px;
            color: rgba(255, 255, 255, 0.95);
            padding: 4px 10px;
            background: rgba(255, 255, 255, 0.15);
            border-radius: 4px;
            display: inline-block;
            backdrop-filter: blur(4px);
            border: 1px solid rgba(255, 255, 255, 0.2);
        }

        .quick-buttons {
            display: flex;
            flex-direction: column;
            gap: 6px;
            margin-top: 12px;
        }

        .update-time {
            position: absolute;
            top: 18px;
            right: 60px;
            font-size: 12px;
            color: rgba(255, 255, 255, 0.8);
        }

        .quick-button {
            padding: 8px 12px;
            gap: 8px;
            background: #1677ff;
            color: white;
            border-radius: 6px;
            display: flex;
            align-items: center;
            transition: all 0.3s ease;
            cursor: pointer;
        }

        .quick-button i {
            width: 14px;
            height: 14px;
            font-size: 12px;
            margin-right: 6px;
            color: white;
        }

        .quick-button span {
            font-size: 12px;
            font-weight: 500;
            color: white;
        }

        .device-info-container {
            display: flex;
            flex-direction: column;
            gap: 6px;
            margin-top: 12px;
        }

        .device-card {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 10px 12px;
            background: #f8f9fa;
            border: 1px solid #e1e4e8;
            border-radius: 8px;
            transition: transform 0.2s ease;
        }

        .device-card h4 {
            color: #666;
            margin: 0;
            font-size: 12px;
            font-weight: 500;
        }

        .device-value {
            font-size: 12px;
            font-weight: 500;
            color: #4776E6;
        }

        .token-stats {
            display: grid;
            grid-template-columns: repeat(3, 1fr);
            gap: 16px;
            margin-bottom: 24px;
        }

        .stat-card {
            background: white;
            padding: 16px;
            border-radius: 16px;
            text-align: left;
            border: 1px solid #e1e4e8;
            display: flex;
            align-items: center;
            gap: 12px;
        }

        .stat-card .icon-wrapper {
            width: 40px;
            height: 40px;
            border-radius: 10px;
            display: flex;
            align-items: center;
            justify-content: center;
        }

        .stat-card:nth-child(1) .icon-wrapper {
            background: rgba(76, 175, 80, 0.1);
        }

        .stat-card:nth-child(2) .icon-wrapper {
            background: rgba(71, 118, 230, 0.1);
        }

        .stat-card:nth-child(3) .icon-wrapper {
            background: rgba(156, 39, 176, 0.1);
        }

        .stat-card i {
            font-size: 20px;
        }

        .stat-card:nth-child(1) i {
            color: #4CAF50;
        }

        .stat-card:nth-child(2) i {
            color: #4776E6;
        }

        .stat-card:nth-child(3) i {
            color: #9C27B0;
        }

        .stat-card .content {
            display: flex;
            flex-direction: column;
            gap: 4px;
        }

        .stat-card .label {
            font-size: 13px;
            color: #666;
        }

        .stat-card .value {
            font-size: 18px;
            font-weight: 600;
            color: #2d3436;
        }

        .action-buttons {
            display: grid;
            grid-template-columns: repeat(2, 1fr);
            gap: 12px;
        }

        .action-button {
            padding: 10px 16px;
            border: none;
            border-radius: 8px;
            background: linear-gradient(135deg, #4776E6, #8E54E9);
            color: white;
            font-size: 13px;
            font-weight: 500;
            letter-spacing: 0.5px;
            cursor: pointer;
            transition: all 0.3s ease;
        }

        .action-button:hover {
            transform: translateY(-2px);
            box-shadow: 0 4px 12px rgba(71, 118, 230, 0.2);
        }

        .console-line {
            display: flex;
            align-items: flex-start;
            margin-bottom: 8px;
            opacity: 0;
            animation: fadeIn 0.2s ease forwards;
        }

        @keyframes fadeIn {
            from {
                opacity: 0;
                transform: translateY(4px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }

        .console-prompt {
            color: #7cbe65;
            margin-right: 8px;
            font-weight: 500;
            -webkit-user-select: none;
            user-select: none;
        }

        .console-text {
            color: #e4e4e4;
        }

        .console-success {
            color: #7cbe65;
        }

        .console-error {
            color: #ff6b6b;
        }

        .console-warning {
            color: #ffd93d;
        }

        .console-info {
            color: #6fb0ff;
        }

        .update-time {
            margin-bottom: 12px;
            font-size: 11px;
        }

        .quick-button {
            padding: 10px 12px;
            gap: 8px;
            background: #1677ff;
            color: white;
            border-radius: 8px;
            display: flex;
            align-items: center;
            transition: all 0.3s ease;
            cursor: pointer;
        }

        .quick-button:hover {
            transform: translateX(4px);
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
        }

        .quick-button i {
            width: 16px;
            height: 16px;
            font-size: 14px;
            margin-right: 8px;
            color: white;
        }

        .quick-button span {
            font-size: 13px;
            font-weight: 500;
            color: white;
        }

        .quick-button:nth-child(2) {
            background: #10b981;
        }

        .quick-button:nth-child(3) {
            background: #00b5d1;
        }

        .quick-button:nth-child(4) {
            background: #7c3aed;
        }

        .panel-section h3 {
            margin-bottom: 12px;
            font-size: 14px;
            font-weight: 600;
            color: #2d3436;
        }

        .quick-buttons {
            display: flex;
            flex-direction: column;
            gap: 8px;
        }

        @media (max-width: 480px) {
            .quick-button {
                padding: 10px 14px;
            }

            .quick-button i {
                width: 16px;
                height: 16px;
                font-size: 14px;
                margin-right: 8px;
            }

            .quick-button span {
                font-size: 13px;
            }

            .device-card {
                padding: 12px 14px;
            }

            .device-card h4 {
                font-size: 13px;
            }

            .device-value {
                font-size: 13px;
            }
        }

        .token-stats-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 20px;
        }

        .token-stats-header .description {
            font-size: 12px;
            color: #666;
            margin-top: 4px;
        }

        .token-stats-title {
            flex: 1;
        }
        
        .token-stats-title .description {
            font-size: 13px;
            color: #666;
        }

        .refresh-button {
            width: 32px;
            height: 32px;
            display: flex;
            align-items: center;
            justify-content: center;
            border: none;
            background: transparent;
            border-radius: 8px;
            cursor: pointer;
            transition: all 0.3s ease;
            color: #666;
            title: "刷新数据";
            aria-label: "刷新数据";
        }

        .refresh-button i {
            font-size: 16px;
            color: #666;
            transition: all 0.3s ease;
        }

        .refresh-button:hover {
            background: rgba(71, 118, 230, 0.1);
        }

        .refresh-button:hover i {
            color: #4776E6;
            transform: rotate(180deg);
        }

        .token-stats-title {
            flex: 1;
        }

        .right-panel {
            display: flex;
            flex-direction: column;
            gap: 24px;
            height: 100%;
            overflow: hidden; /* 修改这里，防止出现滚动条 */
        }

        /* 添加更新提示对话框样式 */
        .update-dialog {
            display: none;
            position: fixed;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            background: white;
            padding: 24px;
            border-radius: 12px;
            box-shadow: 0 4px 24px rgba(0, 0, 0, 0.15);
            z-index: 1001;
            width: 90%;
            max-width: 400px;
        }

        .update-dialog.show {
            display: block;
        }

        .update-dialog h3 {
            margin-bottom: 16px;
            font-size: 18px;
            color: #2d3436;
        }

        .update-info {
            margin-bottom: 20px;
            font-size: 14px;
            line-height: 1.6;
            color: #4a5568;
            max-height: 200px;
            overflow-y: auto;
        }

        .update-actions {
            display: flex;
            gap: 12px;
            justify-content: flex-end;
        }

        .update-button {
            padding: 8px 16px;
            border: none;
            border-radius: 6px;
            font-size: 14px;
            cursor: pointer;
            transition: all 0.3s ease;
        }

        .update-now {
            background: #4776E6;
            color: white;
        }

        .update-later {
            background: #e2e8f0;
            color: #4a5568;
        }

        .update-button:hover {
            transform: translateY(-1px);
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
        }

        .dialog-overlay {
            display: none;
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: rgba(0, 0, 0, 0.5);
            z-index: 1000;
        }

        .dialog-overlay.show {
            display: block;
        }

        /* 添加提交Token对话框样式 */
        .token-dialog {
            display: none;
            position: fixed;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            background: white;
            padding: 24px;
            border-radius: 12px;
            box-shadow: 0 4px 24px rgba(0, 0, 0, 0.15);
            z-index: 1001;
            width: 90%;
            max-width: 500px;
        }

        .token-dialog.show {
            display: block;
        }

        .token-dialog h3 {
            margin-bottom: 16px;
            font-size: 18px;
            color: #2d3436;
        }

        .token-form {
            display: flex;
            flex-direction: column;
            gap: 16px;
        }

        .form-field {
            display: flex;
            flex-direction: column;
            gap: 8px;
        }

        .form-field label {
            font-size: 14px;
            color: #4a5568;
            font-weight: 500;
        }

        .form-field input {
            padding: 10px 12px;
            border: 1px solid #e2e8f0;
            border-radius: 6px;
            font-size: 14px;
            transition: all 0.3s ease;
        }

        .form-field input:focus {
            outline: none;
            border-color: #4776E6;
            box-shadow: 0 0 0 3px rgba(71, 118, 230, 0.1);
        }

        .token-actions {
            display: flex;
            gap: 12px;
            justify-content: flex-end;
            margin-top: 20px;
        }

        .token-button {
            padding: 8px 16px;
            border: none;
            border-radius: 6px;
            font-size: 14px;
            cursor: pointer;
            transition: all 0.3s ease;
        }

        .submit-token {
            background: #4776E6;
            color: white;
        }

        .cancel-token {
            background: #e2e8f0;
            color: #4a5568;
        }

        .token-button:hover {
            transform: translateY(-1px);
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
        }

        /* 添加消息提示样式 */
        .message-box {
            position: fixed;
            top: 20px;
            left: 50%;
            transform: translateX(-50%);
            padding: 12px 24px;
            border-radius: 8px;
            color: white;
            font-size: 14px;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
            z-index: 1000;
            transition: all 0.3s ease;
            display: flex;
            align-items: center;
            gap: 8px;
        }

        .message-success {
            background-color: #10b981;
        }

        .message-error {
            background-color: #ef4444;
        }

        .message-info {
            background-color: #3b82f6;
        }

        .loading-spinner {
            display: inline-block;
            width: 16px;
            height: 16px;
            border: 2px solid rgba(255, 255, 255, 0.3);
            border-radius: 50%;
            border-top-color: #fff;
            animation: spin 1s ease-in-out infinite;
        }

        @keyframes spin {
            to {
                transform: rotate(360deg);
            }
        }

        /* 优化刷新按钮动画 */
        .refresh-button {
            position: relative;
            overflow: hidden;
        }

        .refresh-button::after {
            content: '';
            position: absolute;
            top: 50%;
            left: 50%;
            width: 0;
            height: 0;
            background: rgba(71, 118, 230, 0.2);
            border-radius: 50%;
            transform: translate(-50%, -50%);
            transition: width 0.3s, height 0.3s;
        }

        .refresh-button:hover::after {
            width: 120%;
            height: 120%;
        }

        .refresh-button i {
            transition: transform 0.5s ease-in-out;
        }

        .refresh-button.rotating i {
            transform: rotate(360deg);
        }

        /* 添加卡片hover效果 */
        .stat-card {
            transform: translateY(0);
            transition: all 0.3s ease;
        }

        .stat-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 8px 16px rgba(0, 0, 0, 0.1);
        }

        /* 添加Token使用情况卡片动画 */
        .token-card {
            transform: translateX(0);
            transition: all 0.3s ease;
        }

        .token-card:hover {
            transform: translateX(5px);
        }

        /* 添加控制台新消息动画 */
        .console-line {
            opacity: 0;
            transform: translateY(10px);
            animation: slideIn 0.3s ease forwards;
        }

        @keyframes slideIn {
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }

        /* 添加数据更新动画 */
        .value-update {
            animation: pulse 0.5s ease;
        }

        @keyframes pulse {
            0% {
                transform: scale(1);
            }
            50% {
                transform: scale(1.1);
            }
            100% {
                transform: scale(1);
            }
        }

        .check-update-icon {
            position: absolute;
            top: 20px;
            right: 20px;
            width: 32px;
            height: 32px;
            border-radius: 8px;
            background: rgba(255, 255, 255, 0.15);
            display: flex;
            align-items: center;
            justify-content: center;
            cursor: pointer;
            transition: all 0.3s ease;
            backdrop-filter: blur(4px);
            border: 1px solid rgba(255, 255, 255, 0.2);
        }

        .check-update-icon i {
            font-size: 14px;
            color: rgba(255, 255, 255, 0.9);
            transition: transform 0.3s ease;
        }

        .check-update-icon:hover {
            background: rgba(255, 255, 255, 0.25);
        }

        .check-update-icon:hover i {
            transform: rotate(180deg);
        }

        /* 修改快捷操作区域样式 */
        .panel-section {
            position: relative;
        }

        .update-time {
            position: absolute;
            top: 18px;
            right: 60px;
            font-size: 12px;
            color: rgba(255, 255, 255, 0.8);
        }

        /* 添加弹框样式 */
        .group-dialog {
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            z-index: 1000;
            display: flex;
            align-items: center;
            justify-content: center;
        }

        .dialog-overlay {
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: rgba(0, 0, 0, 0.5);
            backdrop-filter: blur(4px);
        }

        .dialog-content {
            position: relative;
            background: white;
            border-radius: 12px;
            width: 90%;
            max-width: 480px;
            box-shadow: 0 4px 24px rgba(0, 0, 0, 0.1);
            z-index: 1;
        }

        .dialog-header {
            padding: 20px;
            border-bottom: 1px solid #e2e8f0;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .dialog-header h3 {
            margin: 0;
            font-size: 18px;
            color: #2d3436;
        }

        .close-btn {
            background: none;
            border: none;
            color: #64748b;
            cursor: pointer;
            padding: 8px;
            border-radius: 6px;
            transition: all 0.3s ease;
        }

        .close-btn:hover {
            background: #f1f5f9;
            color: #2d3436;
        }

        .dialog-body {
            padding: 20px;
        }

        .group-item {
            display: flex;
            align-items: center;
            gap: 16px;
            padding: 16px;
            background: #f8fafc;
            border-radius: 8px;
            margin-bottom: 16px;
            transition: all 0.3s ease;
        }

        .group-item:last-child {
            margin-bottom: 0;
        }

        .group-item i {
            font-size: 24px;
            color: #4776E6;
        }

        .group-info {
            flex: 1;
            transition: all 0.3s ease;
        }

        .group-info h4 {
            margin: 0 0 4px 0;
            font-size: 16px;
            color: #2d3436;
        }

        .group-info p {
            margin: 0;
            font-size: 14px;
            color: #64748b;
        }

        .copy-btn {
            padding: 8px 12px;
            background: #4776E6;
            color: white;
            border: none;
            border-radius: 6px;
            cursor: pointer;
            font-size: 13px;
            display: flex;
            align-items: center;
            gap: 6px;
            transition: all 0.3s ease;
        }

        .copy-btn:hover {
            background: #3461c1;
        }

        .copy-btn.copied {
            background: #10b981;
        }

        .group-item:hover {
            background: #f0f2f5;
            transform: translateY(-2px);
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
        }

        .group-item:hover .group-info h4 {
            color: #4776E6;
        }

        /* 添加购买对话框样式 */
        .purchase-dialog {
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            z-index: 1000;
            display: flex;
            align-items: center;
            justify-content: center;
        }

        .purchase-dialog .dialog-content {
            background: white;
            border-radius: 12px;
            padding: 24px;
            width: 90%;
            max-width: 400px;
            box-shadow: 0 4px 24px rgba(0, 0, 0, 0.15);
        }

        .purchase-dialog .dialog-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 16px;
        }

        .purchase-dialog .dialog-body {
            margin-bottom: 24px;
        }

        .purchase-dialog .dialog-footer {
            display: flex;
            justify-content: flex-end;
            gap: 12px;
        }

        .purchase-dialog .cancel-btn {
            padding: 8px 16px;
            border: 1px solid #e2e8f0;
            border-radius: 6px;
            background: white;
            cursor: pointer;
        }

        .purchase-dialog .purchase-btn {
            padding: 8px 16px;
            background: #4776E6;
            color: white;
            border: none;
            border-radius: 6px;
            cursor: pointer;
        }

        .purchase-dialog .purchase-btn:hover {
            background: #3461c1;
        }

        /* 添加联系方式选择弹框样式 */
        .contact-dialog .dialog-content {
            max-width: 400px;
        }

        .contact-options {
            display: flex;
            flex-direction: column;
            gap: 16px;
        }

        .contact-option {
            display: flex;
            align-items: center;
            gap: 16px;
            padding: 16px;
            background: #f8fafc;
            border-radius: 8px;
            transition: all 0.3s ease;
        }

        .contact-option:hover {
            background: #f0f2f5;
            transform: translateY(-2px);
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
        }

        .contact-option i {
            font-size: 24px;
            color: #4776E6;
        }

        .contact-info {
            flex: 1;
        }

        .contact-info h4 {
            margin: 0 0 4px 0;
            font-size: 16px;
            color: #2d3436;
        }

        .contact-info p {
            margin: 0;
            font-size: 14px;
            color: #64748b;
        }

        .contact-option .copy-btn {
            padding: 8px 12px;
            background: #4776E6;
            color: white;
            border: none;
            border-radius: 6px;
            cursor: pointer;
            font-size: 13px;
            display: flex;
            align-items: center;
            gap: 6px;
            transition: all 0.3s ease;
        }

        .contact-option .copy-btn:hover {
            background: #3461c1;
        }

        .contact-option .copy-btn.copied {
            background: #10b981;
        }

        .qq-option i {
            color: #12B7F5;
        }

        .telegram-option i {
            color: #0088cc;
        }

        .section-header {
            display: flex;
            justify-content: space-between;
            align-items: flex-start;  /* 改为顶部对齐 */
            margin-bottom: 20px;
        }
        
        .recharge-btn {
            padding: 8px 16px;
            background: linear-gradient(135deg, #7F5BFF 0%, #5B8DFF 100%);
            color: white;
            border: none;
            border-radius: 20px;
            font-size: 14px;
            cursor: pointer;
            display: flex;
            align-items: center;
            gap: 8px;
            transition: all 0.3s ease;
        }
        
        .recharge-btn:hover {
            transform: translateY(-2px);
            box-shadow: 0 4px 12px rgba(127, 91, 255, 0.2);
        }

        .token-stats-title {
            display: flex;
            flex-direction: column;
            gap: 4px;
        }
        
        .token-stats-title .description {
            font-size: 13px;
            color: #666;
        }
    </style>
</head>
<body>
<div class="dashboard" style="padding-top: 32px;">
    <!-- 左侧面板 -->
    <div class="left-panel">
        <!-- 用户信息区域 -->
        <div class="panel-section">
            <div class="user-info">
                <div class="avatar">
                    <i class="fas fa-user"></i>
                </div>
                <div class="user-details">
                    <h2>加载中...</h2>
                    <p>邮箱：加载中...</p>
                </div>
            </div>
        </div>

        <!-- 快捷操作区域 -->
        <div class="panel-section">
            <h3>快捷操作</h3>
            <div class="quick-buttons">
                <!-- 删除提交Token按钮，添加问题反馈和商务合作按钮 -->
                <div class="quick-button">
                    <i class="fas fa-book"></i>
                    <span>使用说明</span>
                </div>
                <div class="quick-button">
                    <i class="fas fa-users"></i>
                    <span>加入交流群</span>
                </div>
                <div class="quick-button">
                    <i class="fas fa-bug"></i>
                    <span>问题反馈</span>
                </div>
                <div class="quick-button">
                    <i class="fas fa-handshake"></i>
                    <span>商务合作</span>
                </div>
            </div>
        </div>

        <!-- 当前设备信息区域HTML修改 -->
        <div class="panel-section">
            <h3>当前设备信息</h3>
            <div class="device-info-container">
                <div class="device-card">
                    <h4>操作系统</h4>
                    <div class="device-value" id="device-os-info">加载中...</div>
                </div>
                <div class="device-card">
                    <h4>设备名称</h4>
                    <div class="device-value" id="device-name-info">加载中...</div>
                </div>
                <div class="device-card">
                    <h4>IP地址</h4>
                    <div class="device-value" id="device-ip-info">加载中...</div>
                </div>
                <div class="device-card">
                    <h4>MAC地址</h4>
                    <div class="device-value" id="device-mac-info">加载中...</div>
                </div>
            </div>
        </div>
    </div>

    <!-- 右侧面板 -->
    <div class="right-panel">
        <!-- Token次数统计区域的修改 -->
        <div class="panel-section">
            <div class="section-header">
                <div class="token-stats-title">
                    <h3>Token 统计</h3>
                    <div class="description">以下数据显示您的Token获取限制和使用情况</div>
                </div>
            </div>
            <div class="token-stats">
                <div class="stat-card">
                    <div class="icon-wrapper">
                        <i class="fas fa-infinity"></i>
                    </div>
                    <div class="content">
                        <div class="label">总次数</div>
                        <div class="value" id="total_cursors">-</div>
                    </div>
                </div>
                <div class="stat-card">
                    <div class="icon-wrapper">
                        <i class="fas fa-check-circle"></i>
                    </div>
                    <div class="content">
                        <div class="label">剩余次数</div>
                        <div class="value" id="unused_cursors">-</div>
                    </div>
                </div>
                <div class="stat-card">
                    <div class="icon-wrapper">
                        <i class="fas fa-chart-bar"></i>
                    </div>
                    <div class="content">
                        <div class="label">累计使用</div>
                        <div class="value" id="used_cursors">-</div>
                    </div>
                </div>
            </div>
        </div>

        <!-- 操作面板区域 -->
        <div class="panel-section">
            <h3>操作面板</h3>
            <div class="action-buttons">
                <button class="action-button" id="start-task">一键享用</button>
                <button class="action-button" id="reset-machine">重置本机信息</button>
                <button class="action-button" id="disable-update">禁用更新</button>
                <button class="action-button" id="patch-cursor">执行补丁</button>
            </div>
        </div>

        <!-- 运行日志区域 -->
        <div class="panel-section">
            <h3>运行日志</h3>
            <div class="console-wrapper">
                <div class="console">
                    <div class="console-line">
                        <span class="console-prompt">$</span>
                        <span class="console-text console-success">系统初始化完成</span>
                    </div>
                    <div class="console-line">
                        <span class="console-prompt">$</span>
                        <span class="console-text console-info">正在连接服务器...</span>
                    </div>
                    <div class="console-line">
                        <span class="console-prompt">$</span>
                        <span class="console-text console-success">连接成功</span>
                    </div>
                    <div class="console-line">
                        <span class="console-prompt">$</span>
                        <span class="console-text">等待任务执行...</span>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- 添加更新对话框HTML -->
<div class="dialog-overlay"></div>
<div class="update-dialog">
    <h3>发现新版本</h3>
    <div class="update-info"></div>
    <div class="update-actions">
        <button class="update-button update-later">稍后更新</button>
        <button class="update-button update-now">立即更新</button>
    </div>
</div>

<!-- 添加提交Token对话框HTML -->
<div class="token-dialog">
    <h3>提交Token</h3>
    <form class="token-form" onsubmit="return false;">
        <div class="form-field">
            <label for="account">账号</label>
            <input type="text" id="account" required placeholder="请输入Cursor账号">
        </div>
        <div class="form-field">
            <label for="password">密码</label>
            <input type="password" id="password" required placeholder="请输入Cursor密码">
        </div>
        <div class="form-field">
            <label for="token">Token</label>
            <input type="text" id="token" required placeholder="请输入Token">
        </div>
        <div class="form-field">
            <label for="remark">使用者名称</label>
            <input type="text" id="remark" required placeholder="请输入您的名称">
        </div>
        <div class="token-actions">
            <button class="token-button cancel-token">取消</button>
            <button class="token-button submit-token">提交</button>
        </div>
    </form>

</div>

<!-- 加入交流群对话框 -->
<div class="group-dialog" style="display: none;">
    <div class="dialog-overlay"></div>
    <div class="dialog-content">
        <div class="dialog-header">
            <h3>加入交流群</h3>
            <button class="close-btn"><i class="fas fa-times"></i></button>
        </div>
        <div class="dialog-body">
            <!-- QQ交流群信息 -->
            <div class="group-item" onclick="window.open('https://qm.qq.com/q/8fBeUUv6mY', '_blank')" style="cursor: pointer;">
                <i class="fab fa-qq"></i>
                <div class="group-info">
                    <h4>QQ 交流群: 600657255</h4>
                    <p>点击进入交流群</p>
                </div>
                <button class="copy-btn" data-copy="https://qm.qq.com/q/8fBeUUv6mY" onclick="event.stopPropagation()">
                    <i class="fas fa-copy"></i> 复制链接
                </button>
            </div>

            <!-- 商务合作信息 -->
            <div class="group-item" onclick="window.open('https://qm.qq.com/q/8fBeUUv6mY', '_blank')" style="cursor: pointer;">
                <i class="fab fa-qq"></i>
                <div class="group-info">
                    <h4>商务合作，软件开发</h4>
                    <p>联系:782045011</p>
                </div>
                <button class="copy-btn" data-copy="https://qm.qq.com/q/8fBeUUv6mY" onclick="event.stopPropagation()">
                    <i class="fas fa-copy"></i> 复制链接
                </button>
            </div>

            <!-- Telegram群组信息 -->
            <div class="group-item" onclick="window.open('https://t.me/+KNpWzdUoCeQ3OGVl', '_blank')" style="cursor: pointer;">
                <i class="fab fa-telegram"></i>
                <div class="group-info">
                    <h4>Telegram 群组</h4>
                    <p>点击进入交流群</p>
                </div>
                <button class="copy-btn" data-copy="https://t.me/+KNpWzdUoCeQ3OGVl" onclick="event.stopPropagation()">
                    <i class="fas fa-copy"></i> 复制链接
                </button>
            </div>
        </div>
    </div>
</div>

<script>
    /**
     * 加载用户信息
     * 从AppState或API获取用户信息并更新显示
     */
    async function loadUserInfo() {
        try {
            // 尝试从AppState获取数据
            let userInfo = AppState.userInfo;
            let membershipInfo = AppState.membershipInfo;
            
            // 如果状态中没有数据，则重新请求
            if (!userInfo || !membershipInfo) {
                const data = await API.loadInitialData();
                userInfo = data.userInfo;
                membershipInfo = data.membershipInfo;
            }
            
            // 更新用户信息显示
            updateUserDisplay(userInfo);
            
            // 更新会员信息显示
            updateMembershipDisplay(membershipInfo);
            
        } catch (error) {
            console.error('加载用户信息失败:', error);
            setDefaultUserDisplay();
        }
    }

    // 统计数据获取函数
    function loadInitialStats() {
        const loadingMessage = showMessage('正在加载统计数据...', 'info', true);
        
        // 添加重试逻辑
        const retryLoad = (retries = 3) => {
            fetch(`${BASE_URL}/api/cursor/my-stats`, {
                method: 'GET',
                headers: {
                    'Content-Type': 'application/json',
                    'Authorization': localStorage.getItem('access_token')
                }
            })
            .then(response => {
                if (!response.ok) {
                    throw new Error(`HTTP error! status: ${response.status}`);
                }
                return response.json();
            })
            .then(result => {
                loadingMessage?.remove();
                console.log('统计数据响应:', result);

                if (result.code === 200) {
                    const stats = result.data;
                    
                    // 更新显示数据
                    document.getElementById('total_cursors').textContent = stats.total_cursors.toLocaleString();
                    document.getElementById('unused_cursors').textContent = stats.unused_cursors.toLocaleString();
                    document.getElementById('used_cursors').textContent = stats.used_cursors.toLocaleString();

                    // 添加更新动画
                    ['total_cursors', 'unused_cursors', 'used_cursors'].forEach(id => {
                        const el = document.getElementById(id);
                        el.classList.add('value-update');
                        setTimeout(() => el.classList.remove('value-update'), 500);
                    });

                    showMessage('统计数据已更新', 'success');
                } else {
                    throw new Error(result.msg || '获取数据失败');
                }
            })
            .catch(error => {
                console.error('加载统计数据失败:', error);
                if (retries > 0) {
                    console.log(`重试加载统计数据，剩余重试次数: ${retries - 1}`);
                    setTimeout(() => retryLoad(retries - 1), 1000);
                } else {
                    loadingMessage?.remove();
                    showMessage(`加载统计数据失败: ${error.message}`, 'error');
                }
            });
        };

        // 开始加载，带重试机制
        retryLoad();
    }

    // 刷新按钮事件处理
    document.querySelector('.refresh-button').addEventListener('click', function () {
        const button = this;
        button.classList.add('rotating');

        loadInitialStats();

        setTimeout(() => {
            button.classList.remove('rotating');
        }, 500);
    });

    // 页面加载时调用
    document.addEventListener('DOMContentLoaded', loadInitialStats);


    // 添加退出登录功能
    function logout() {
        localStorage.removeItem('access_token');
        localStorage.removeItem('user_info');
        window.location.href = '/';
    }

    // 绑定退出登录事件（如果有退出按钮的话）
    const logoutButton = document.querySelector('.logout-button');
    if (logoutButton) {
        logoutButton.addEventListener('click', logout);
    }

    // 添加版本号更新函数
    function updateVersionInfo() {
        const versionElement = document.querySelector('.version-info');
        fetch(`${BASE_URL}/api/version`)  // 这里需要修改
            .then(response => response.json())
            .then(data => {
                if (data.code === 200) {
                    versionElement.textContent = `版本号：${data.data.version}`;
                }
            })
            .catch(error => {
                console.error('获取版本号失败:', error);
                versionElement.textContent = '版本号：v1.0.0';  // 默认版本号
            });
    }

    // 修改检查更新功能
    async function checkUpdate() {
        try {
            const loadingMessage = showMessage('正在检查更新...', 'info', true);
            const response = await fetch(`${BASE_URL}/api/app/check-update`, {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json',
                    'Authorization': `${localStorage.getItem('access_token')}`
                },
                body: JSON.stringify({
                    app_name: 'CursorTask',
                    current_version: '1.0.0'
                })
            });

            const result = await response.json();
            loadingMessage.remove();

            if (result.code === 200) {
                if (result.msg === '当前已是最新版本') {
                    showMessage(result.msg, 'success');
                } else {
                    const {version, update_info, download_url} = result.data;
                    showUpdateDialog(version, update_info, download_url);
                    // 默认禁用所有导航链接
                    disableNavigation();
                }
            } else {
                throw new Error(result.msg || '检查更新失败');
            }
        } catch (error) {
            console.error('检查更新失败:', error);
            showMessage(error.message, 'error');
        }
    }

    // 显示更新对话框
    function showUpdateDialog(version, updateInfo, downloadUrl) {
        const dialog = document.querySelector('.update-dialog');
        const overlay = document.querySelector('.dialog-overlay');
        const updateInfoElement = dialog.querySelector('.update-info');

        updateInfoElement.innerHTML = `
        <p><strong>最新版本：</strong>${version}</p>
        <p><strong>更新内容：</strong></p>
        <p>${updateInfo}</p>
    `;

        dialog.classList.add('show');
        overlay.classList.add('show');

        // 绑定按钮事件
        const updateNowButton = dialog.querySelector('.update-now');
        const updateLaterButton = dialog.querySelector('.update-later');

        updateNowButton.onclick = () => {
            window.open(downloadUrl, '_blank');
            hideUpdateDialog();
        };

        updateLaterButton.onclick = hideUpdateDialog;
    }

    // 隐藏更新对话框
    function hideUpdateDialog() {
        const dialog = document.querySelector('.update-dialog');
        const overlay = document.querySelector('.dialog-overlay');
        dialog.classList.remove('show');
        overlay.classList.remove('show');
    }

    // 修改提交Token功能
    async function submitToken() {
        const account = document.getElementById('account').value.trim();
        const password = document.getElementById('password').value.trim(); // 改为password
        const token = document.getElementById('token').value.trim(); // 改为单个token
        const remark = document.getElementById('remark').value.trim();

        if (!account || !password || !token || !remark) {
            showMessage('请填写完整信息', 'error');
            return;
        }

        try {
            const submitButton = document.querySelector('.token-button.submit-token');
            submitButton.disabled = true;
            submitButton.innerHTML = '<div class="loading-spinner"></div> 提交中...';

            const response = await fetch(`${BASE_URL}/api/cursor/external`, {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json',
                    'Authorization': `${localStorage.getItem('access_token')}`
                },
                body: JSON.stringify({
                    account,
                    password,    // 更新为password
                    token,      // 更新为token
                    remark
                })
            });

            const result = await response.json();

            if (result.code === 200) {
                showMessage('Token提交成功', 'success');
                hideTokenDialog();
                // 刷新Token统计数据
                await loadInitialStats();
            } else {
                throw new Error(result.msg || '提交失败');
            }
        } catch (error) {
            console.error('提交Token失败:', error);
            toast.error(`提交失败: ${error.message}`);
        } finally {
            const submitButton = document.querySelector('.token-button.submit-token');
            submitButton.disabled = false;
            submitButton.textContent = '提交';
        }
    }


    // 优化消息提示函数
    function showMessage(message, type = 'info', loading = false) {
        // 移除现有的消息框
        const existingMessage = document.querySelector('.message-box');
        if (existingMessage) {
            existingMessage.remove();
        }

        const messageBox = document.createElement('div');
        messageBox.className = `message-box message-${type}`;

        // 如果是加载状态，添加加载动画
        if (loading) {
            messageBox.innerHTML = `
            <div class="loading-spinner"></div>
            <span>${message}</span>
        `;
        } else {
            messageBox.textContent = message;
        }

        document.body.appendChild(messageBox);

        // 如果不是加载状态，3秒后自动消失
        if (!loading) {
            setTimeout(() => {
                messageBox.style.opacity = '0';
                setTimeout(() => messageBox.remove(), 3000);
            }, 3000);
        }

        return messageBox; // 返回消息框元素，方便后续移除
    }

    // 优化对话框关闭逻辑
    function hideTokenDialog() {
        const dialog = document.querySelector('.token-dialog');
        const overlay = document.querySelector('.dialog-overlay');
        dialog.classList.remove('show');
        overlay.classList.remove('show');
        // 清空表单
        const form = dialog.querySelector('.token-form');
        if (form) {
            form.reset();
        }
    }

    // 添加表单验证
    document.querySelectorAll('.token-form input').forEach(input => {
        input.addEventListener('input', function () {
            const field = this.closest('.form-field');
            if (this.value.trim()) {
                field.classList.remove('error');
                const errorMessage = field.querySelector('.error-message');
                if (errorMessage) {
                    errorMessage.remove();
                }
            }
        });
    });

    // 绑定检查更新按钮点击事件
    const checkUpdateBtn = document.querySelector('.quick-button.check-update');
    if (checkUpdateBtn) {
        checkUpdateBtn.addEventListener('click', function() {
            checkUpdate();
        });
    }

    // 更新版本号显示
    const versionElement = document.querySelector('.version-info');
    versionElement.textContent = '版本号：v1.1.0';

    // 添加提交Token相关函数
    function showTokenDialog() {
        const dialog = document.querySelector('.token-dialog');
        const overlay = document.querySelector('.dialog-overlay');
        dialog.classList.add('show');
        overlay.classList.add('show');
        
        // 绑定取消按钮事件
        const cancelBtn = dialog.querySelector('.token-button.cancel-token');
        if (cancelBtn) {
            cancelBtn.removeEventListener('click', hideTokenDialog);  // 先移除旧的事件监听器
            cancelBtn.addEventListener('click', hideTokenDialog);
        }
        
        // 绑定遮罩层点击事件
        overlay.removeEventListener('click', hideTokenDialog);  // 先移除旧的事件监听器
        overlay.addEventListener('click', hideTokenDialog);
        
        // 阻止对话框点击事件冒泡
        dialog.removeEventListener('click', (e) => e.stopPropagation());  // 先移除旧的事件监听器
        dialog.addEventListener('click', (e) => e.stopPropagation());

        // 确保提交按钮事件绑定
        const submitBtn = dialog.querySelector('.token-button.submit-token');
        if (submitBtn) {
            submitBtn.removeEventListener('click', submitToken);  // 先移除旧的事件监听器
            submitBtn.addEventListener('click', submitToken);
        }
    }

    // 绑定事件
    document.querySelector('.quick-button.submit-token-btn').addEventListener('click', showTokenDialog);
    document.querySelector('.token-button.cancel-token').addEventListener('click', hideTokenDialog);
    document.querySelector('.token-button.submit-token').addEventListener('click', submitToken);
    document.querySelector('.dialog-overlay').addEventListener('click', hideTokenDialog);

    // 优化数据更新函数
    function updateTokenStats(userData) {
        // ... 现有代码 ...

        // 添加更新动画
        const elements = document.querySelectorAll('.stat-card .value, .token-value');
        elements.forEach(el => {
            el.style.opacity = '0';
            setTimeout(() => {
                el.style.opacity = '1';
                el.classList.add('value-update');
                setTimeout(() => el.classList.remove('value-update'), 500);
            }, 100);
        });
    }

    // 优化控制台输出
    function addConsoleMessage(message, type = 'info') {
        const console = document.querySelector('.console');
        const line = document.createElement('div');
        line.className = 'console-line';
        line.innerHTML = `
        <span class="console-prompt">$</span>
        <span class="console-text console-${type}">${message}</span>
    `;
        console.appendChild(line);
        console.scrollTop = console.scrollHeight;
    }

    // 确保脚本在页面加载和动态加载时都能正常工作
    function initializeEventListeners() {
        console.log('初始化主页事件监听器...');

        // 先初始化数据，确保DOM元素都已加载
        initializeMainPage();

        // 等待一个微任务周期，确保DOM完全加载
        Promise.resolve().then(() => {
            console.log('绑定主页事件监听器...');

            // 刷新按钮事件处理
            const refreshButton = document.querySelector('.refresh-button');
            if (refreshButton) {
                console.log('找到刷新按钮，绑定事件');
                refreshButton.addEventListener('click', function () {
                    const button = this;
                    button.classList.add('rotating');
                    loadInitialStats();
                    setTimeout(() => {
                        button.classList.remove('rotating');
                    }, 500);
                });
            }

            // 使用说明点击事件
            const usageGuideBtn = document.querySelector('.quick-button:nth-child(1)');
            if (usageGuideBtn) {
                console.log('找到使用说明按钮，绑定事件');
                usageGuideBtn.addEventListener('click', function () {
                    showMessage('使用说明功能即将上线，敬请期待！', 'info');
                });
            }

            // 加入交流群点击事件
            const joinGroupBtn = document.querySelector('.quick-button:nth-child(2)');
            if (joinGroupBtn) {
                console.log('找到加入交流群按钮，绑定事件');
                joinGroupBtn.addEventListener('click', function () {
                    alert('请扫描二维码加入交流群！\n（二维码功能开发中）');
                });
            }

            // 检查更新按钮事件
            const checkUpdateBtn = document.querySelector('.quick-button.check-update');
            if (checkUpdateBtn) {
                console.log('找到检查更新按钮，绑定事件');
                checkUpdateBtn.addEventListener('click', checkUpdate);
            }

            // 提交Token按钮事件
            const submitTokenBtn = document.querySelector('.quick-button.submit-token-btn');
            if (submitTokenBtn) {
                console.log('找到提交Token按钮，绑定事件');
                submitTokenBtn.addEventListener('click', showTokenDialog);
            }

            // 绑定对话框相关事件
            const cancelTokenBtn = document.querySelector('.token-button.cancel-token');
            if (cancelTokenBtn) {
                console.log('找到取消按钮，绑定事件');
                cancelTokenBtn.addEventListener('click', hideTokenDialog);
            }

            const submitTokenFormBtn = document.querySelector('.token-button.submit-token');
            if (submitTokenFormBtn) {
                console.log('找到提交按钮，绑定事件');
                submitTokenFormBtn.addEventListener('click', submitToken);
            }

            const dialogOverlay = document.querySelector('.dialog-overlay');
            if (dialogOverlay) {
                console.log('找到对话框遮罩，绑定事件');
                dialogOverlay.addEventListener('click', hideTokenDialog);
            }

            // 阻止对话框点击事件冒泡
            const tokenDialog = document.querySelector('.token-dialog');
            if (tokenDialog) {
                console.log('找到Token对话框，绑定事件');
                tokenDialog.addEventListener('click', (e) => {
                    e.stopPropagation();
                });
            }
        });
    }

    // 添加页面初始化函数
    function initializeMainPage() {
        console.log('初始化主页数据...');
        // 加载用户信息
        loadUserInfo();
        // 加载统计数据
        loadInitialStats();
        // 加载设备信息
        loadDeviceInfo();
        // 初始化按钮事件
        initializeButtons();
    }

    // 添加显示弹框函数
    function showGroupDialog() {
        const dialog = document.querySelector('.group-dialog');
        dialog.style.display = 'flex';

        // 绑定关闭按钮事件
        const closeBtn = dialog.querySelector('.close-btn');
        const overlay = dialog.querySelector('.dialog-overlay');

        closeBtn.onclick = () => {
            dialog.style.display = 'none';
        };

        overlay.onclick = () => {
            dialog.style.display = 'none';
        };

        // 绑定复制按钮事件
        dialog.querySelectorAll('.copy-btn').forEach(btn => {
            btn.onclick = async () => {
                const textToCopy = btn.dataset.copy;
                try {
                    await navigator.clipboard.writeText(textToCopy);
                    btn.classList.add('copied');
                    btn.innerHTML = '<i class="fas fa-check"></i> 已复制';
                    setTimeout(() => {
                        btn.classList.remove('copied');
                        btn.innerHTML = '<i class="fas fa-copy"></i> 复制' +
                            (btn.closest('.group-item').querySelector('i').classList.contains('fa-qq') ? '群号' : '链接');
                    }, 2000);
                } catch (err) {
                    console.error('复制失败:', err);
                }
            };
        });
    }

    // 添加加载设备信息的函数
    async function loadDeviceInfo() {
        try {
            const baseUrl = window.location.origin;  // 动态获取当前页面的基础URL
            const response = await fetch(`${baseUrl}/api/device/info`, {
                headers: {
                    'Authorization': localStorage.getItem('access_token')
                }
            });

            const result = await response.json();

            if (result.code === 200) {
                const deviceInfo = result.data;

                // 更新设备信息显示
                // 使用新的 ID 更新设备信息显示
                document.getElementById('device-os-info').textContent = deviceInfo.os_name;
                document.getElementById('device-name-info').textContent = deviceInfo.device_name;
                document.getElementById('device-ip-info').textContent = deviceInfo.ip_address;
                document.getElementById('device-mac-info').textContent = deviceInfo.mac_address;

                // 添加更新动画
                document.querySelectorAll('.token-card .token-value').forEach(el => {
                    el.classList.add('value-update');
                    setTimeout(() => el.classList.remove('value-update'), 500);
                });

                // 添加成功消息
                showMessage('设备信息加载成功', 'success');
            } else {
                throw new Error(result.msg || '获取设备信息失败');
            }
        } catch (error) {
            console.error('加载设备信息失败:', error);
            showMessage('加载设备信息失败: ' + error.message, 'error');

            // 显示错误状态
            ['os-info', 'cpu-info', 'memory-info', 'disk-info'].forEach(id => {
                document.getElementById(id).textContent = '加载失败';
            });
        }
    }

    // 清空控制台日志
    function clearConsole() {
        const console = document.querySelector('.console');
        console.innerHTML = '';
    }

    // 添加控制台日志
    function addConsoleLog(message, type = 'info') {
        const console = document.querySelector('.console');
        const line = document.createElement('div');
        line.className = 'console-line';
        line.innerHTML = `
        <span class="console-prompt">$</span>
        <span class="console-text console-${type}">${message}</span>
    `;
        console.appendChild(line);
        console.scrollTop = console.scrollHeight;

        // 添加渐入动画
        line.style.opacity = '0';
        setTimeout(() => {
            line.style.opacity = '1';
        }, 10);
    }

    // 初始化按钮事件
    async function initializeButtons() {
        console.log('初始化按钮事件...');
        
        // 一键享用
        document.getElementById('start-task').addEventListener('click', async () => {
            try {
                clearConsole();
                addConsoleLog('开始执行一键享用...', 'info');
                
                const token = localStorage.getItem('access_token');
                if (!token) {
                    addConsoleLog('未找到登录凭证，请先登录', 'error');
                    return;
                }
                //调用本项目服务的不需要前缀
                const response = await fetch(`/cursor/update`, {
                    method: 'POST',
                    headers: {
                        'Authorization': token
                    }
                });
                
                const result = await response.json();
                
                // 新的检查使用限制逻辑
                if (result.code === 403) {
                    addConsoleLog('您的使用次数已用完，请到个人中心页面进行套餐续费', 'warning');
                    showMessage('您的使用次数已用完，请到个人中心页面进行套餐续费', 'warning');
                    return;
                }
                
                if (result.code === 200) {
                    addConsoleLog('更新成功!', 'success');
                    if (result.data) {
                        addConsoleLog(`版本: ${result.data.version}`, 'info');
                        addConsoleLog(`邮箱: ${result.data.email}`, 'info');
                        if (result.data.need_patch) {
                            addConsoleLog('已应用补丁', 'info');
                        }
                        if (result.data.token_info) {
                            addConsoleLog('Token信息:', 'info');
                            addConsoleLog(`账号: ${result.data.token_info.account}`, 'info');
                            addConsoleLog(`备注: ${result.data.token_info.remark}`, 'info');
                        }
                    }
                } else {
                    // 检查错误消息中是否包含使用限制信息
                    if (result.msg && result.msg.includes("已达到每日使用限制")) {
                        addConsoleLog('您的使用次数已用完，请到个人中心页面进行套餐续费', 'warning');
                        showMessage('您的使用次数已用完，请到个人中心页面进行套餐续费', 'warning');
                        return;
                    }
                    addConsoleLog(`更新失败: ${result.msg}`, 'error');
                }
            } catch (error) {
                addConsoleLog(`执行出错: ${error.message}`, 'error');
            }
        });

        // 重置本机信息
        //调用本项目服务的不需要前缀
        document.getElementById('reset-machine').addEventListener('click', async () => {
            try {
                clearConsole();
                addConsoleLog('开始重置本机信息...', 'info');
                
                const response = await fetch(`/cursor/reset-machine-id`, {
                    method: 'POST',
                    headers: {
                        'Authorization': localStorage.getItem('access_token')
                    }
                });
                
                const result = await response.json();
                if (result.code === 200) {
                    addConsoleLog('重置成功!', 'success');
                    if (result.data) {
                        addConsoleLog('原机器码:', 'info');
                        Object.entries(result.data.old_ids).forEach(([key, value]) => {
                            addConsoleLog(`${key}: ${value}`, 'info');
                        });
                        addConsoleLog('新机器码:', 'info');
                        Object.entries(result.data.new_ids).forEach(([key, value]) => {
                            addConsoleLog(`${key}: ${value}`, 'info');
                        });
                    }
                } else {
                    addConsoleLog(`重置失败: ${result.msg}`, 'error');
                }
            } catch (error) {
                addConsoleLog(`执行出错: ${error.message}`, 'error');
            }
        });

        // 禁用更新
        //调用本项目服务的不需要前缀
        document.getElementById('disable-update').addEventListener('click', async () => {
            try {
                clearConsole();
                addConsoleLog('开始禁用自动更新...', 'info');
                
                const response = await fetch(`/cursor/disable-update`, {
                    method: 'POST',
                    headers: {
                        'Authorization': localStorage.getItem('access_token')
                    }
                });
                
                const result = await response.json();
                if (result.code === 200) {
                    addConsoleLog(result.msg, 'success');
                } else {
                    addConsoleLog(`禁用失败: ${result.msg}`, 'error');
                }
            } catch (error) {
                addConsoleLog(`执行出错: ${error.message}`, 'error');
            }
        });

        // 执行补丁
        //调用本项目服务的不需要前缀
        document.getElementById('patch-cursor').addEventListener('click', async () => {
            try {
                clearConsole();
                addConsoleLog('开始执行补丁操作...', 'info');
                
                const response = await fetch(`/cursor/patch`, {
                    method: 'POST',
                    headers: {
                        'Authorization': localStorage.getItem('access_token')
                    }
                });
                
                const result = await response.json();
                if (result.code === 200) {
                    addConsoleLog('补丁执行成功!', 'success');
                    if (result.data) {
                        addConsoleLog(`版本: ${result.data.version}`, 'info');
                        if (result.data.patched) {
                            addConsoleLog('已成功应用补丁', 'success');
                        } else {
                            addConsoleLog('当前版本无需补丁', 'info');
                        }
                    }
                } else {
                    addConsoleLog(`补丁执行失败: ${result.msg}`, 'error');
                }
            } catch (error) {
                addConsoleLog(`执行出错: ${error.message}`, 'error');
            }
        });

        // 快捷操作按钮
        const submitTokenBtn = document.querySelector('.quick-button.submit-token-btn');
        if (submitTokenBtn) {
            submitTokenBtn.addEventListener('click', showTokenDialog);
        }

        const usageGuideBtn = document.querySelector('.quick-button:nth-child(1)');
        if (usageGuideBtn) {
            usageGuideBtn.addEventListener('click', () => {
                showMessage('使用说明功能即将上线，敬请期待！', 'info');
            });
        }

        const joinGroupBtn = document.querySelector('.quick-button:nth-child(2)');
        if (joinGroupBtn) {
            joinGroupBtn.addEventListener('click', showGroupDialog);
        }

        const feedbackBtn = document.querySelector('.quick-button:nth-child(3)');
        if (feedbackBtn) {
            feedbackBtn.addEventListener('click', () => {
                window.open('http://wpa.qq.com/msgrd?v=3&uin=782045011&site=qq&menu=yes', '_blank');
            });
        }

        const businessBtn = document.querySelector('.quick-button:nth-child(4)');
        if (businessBtn) {
            businessBtn.addEventListener('click', () => {
                // 直接打开QQ联系方式
                window.open('http://wpa.qq.com/msgrd?v=3&uin=782045011&site=qq&menu=yes', '_blank');
            });
        }

        console.log('按钮事件初始化完成');
    }

    // 修改显示购买对话框的函数
    function showPurchaseDialog() {
        const dialog = document.querySelector('.purchase-dialog');
        dialog.style.display = 'flex';
        
        // 绑定关闭按钮事件
        const closeBtn = dialog.querySelector('.close-btn');
        if (closeBtn) {
            closeBtn.onclick = () => {
                dialog.style.display = 'none';
            };
        }
        
        // 绑定取消按钮事件
        const cancelBtn = dialog.querySelector('.cancel-btn');
        if (cancelBtn) {
            cancelBtn.onclick = () => {
                dialog.style.display = 'none';
            };
        }
        
        // 绑定复制按钮事件
        dialog.querySelectorAll('.copy-btn').forEach(btn => {
            btn.onclick = async (e) => {
                e.stopPropagation();
                const contactInfo = btn.dataset.contact;
                try {
                    await navigator.clipboard.writeText(contactInfo);
                    btn.classList.add('copied');
                    const originalText = btn.innerHTML;
                    btn.innerHTML = '<i class="fas fa-check"></i> 已复制';
                    setTimeout(() => {
                        btn.classList.remove('copied');
                        btn.innerHTML = originalText;
                    }, 2000);
                    showMessage('联系方式已复制到剪贴板', 'success');
                } catch (err) {
                    console.error('复制失败:', err);
                    showMessage('复制失败，请手动复制', 'error');
                }
            };
        });
        
        // 点击遮罩层关闭对话框
        const overlay = dialog.querySelector('.dialog-overlay');
        if (overlay) {
            overlay.onclick = () => {
                dialog.style.display = 'none';
            };
        }
    }

    // 导出初始化函数到全局作用域
    window.initializeMainPage = initializeMainPage;
    window.initializeEventListeners = initializeEventListeners;

    // 页面加载完成后初始化
    document.addEventListener('DOMContentLoaded', () => {
        console.log('页面加载完成，开始初始化...');
        initializeMainPage();
        initializeEventListeners();
        initializeButtons();
        
        // 添加这一行，确保加载统计数据
        loadInitialStats();
    });

    // 添加用户信息显示函数
    function updateUserDisplay(userInfo) {
        if (!userInfo) return;
        
        const { username, email, role } = userInfo;
        
        // 更新用户信息显示
        document.querySelector('.user-details h2').textContent = username || '未知用户';
        document.querySelector('.user-details p').textContent = `邮箱：${email || '未知'}`;

        // 更新角色信息
        const userDetails = document.querySelector('.user-details');
        let roleElement = userDetails.querySelector('.user-role');
        
        if (!roleElement) {
            roleElement = document.createElement('p');
            roleElement.className = 'user-role';
            userDetails.appendChild(roleElement);
        }
        
        roleElement.textContent = `角色：${role?.name || '普通用户'}`;

        // 添加渐入动画
        document.querySelector('.user-info').style.opacity = '0';
        setTimeout(() => {
            document.querySelector('.user-info').style.opacity = '1';
        }, 100);
    }

    // 添加默认显示函数
    function setDefaultUserDisplay() {
        document.querySelector('.user-details h2').textContent = '未登录用户';
        document.querySelector('.user-details p').textContent = '邮箱：未登录';
        
        const roleElement = document.querySelector('.user-role');
        if (roleElement) {
            roleElement.textContent = '角色：未知';
        }
    }

    // 添加会员信息显示函数
    function updateMembershipDisplay(membershipInfo) {
        if (!membershipInfo) return;
        
        const { membership, limits } = membershipInfo;
        
        // 更新会员信息显示
        // ... 根据实际UI结构更新会员信息 ...
    }

    // 添加页面可见性变化监听
    document.addEventListener('visibilitychange', () => {
        if (document.visibilityState === 'visible') {
            console.log('页面变为可见，重新加载统计数据');
            loadInitialStats();
        }
    });

    // 添加路由变化监听（如果使用了前端路由）
    window.addEventListener('popstate', () => {
        console.log('检测到路由变化，重新加载统计数据');
        loadInitialStats();
    });
</script>
</body>
</html>
